/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/



#if !defined(AFX_PGLMAPVECTOR_H__70867AFB_7D0F_4F2B_8187_6103E59B8EAA__INCLUDED_)
#define AFX_PGLMAPVECTOR_H__70867AFB_7D0F_4F2B_8187_6103E59B8EAA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLMap.h>

/*! \brief A vector filed on evenly spaced lattice.

\ingroup PGLMapGroup
This objects implement a vector field.

\image html vectorf.png "A vector field"
*/
class PGLCORE_EXT_CLASS CPGLMapVector : public CPGLMap  
{
PGL_DECLARE_DYNCREATE(CPGLMapVector);
public:
	//! \name Constructors
	//@{
	//! Default constructor
	CPGLMapVector();
	//! Copy constructor
	CPGLMapVector(const CPGLMapVector& l){*this=l;};
	/// assignment constructor
	CPGLMapVector& operator = (const CPGLMapVector& l);
	/// destructor
	~CPGLMapVector();
	//@}

	//! \name Data setters and getters
	//@{
	/*! \brief Setting data as vectors of double
	Sets the array $V_x$ must be of size \f$n_x \times n_y\f$. 
	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.

	\param vx x part of the vector field such that \f$v_x[i*n_x+j] = v_x(i,j)\f$
	\param vy y part of the vector field such that \f$v_y[i*n_x+j] = v_x(i,j)\f$ 
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetDatas(const std::vector<double>& vx, const std::vector<double>& vy, bool bMakeCopy = true);
	/*! \brief Setting data as vectors of double
	Sets the array $V_x$ must be of size \f$n_x \times n_y\f$. 
	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.

	\param vx x part of the vector field such that \f$v_x[i*n_x+j] = v_x(i,j)\f$
	\param vy y part of the vector field such that \f$v_y[i*n_x+j] = v_x(i,j)\f$ 
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetDatas(const std::vector<float>& vx, const std::vector<float>& vy, bool bMakeCopy = true);
	/*! \brief Setting data as vectors of double
	Sets the array $V_x$ must be of size \f$n_x \times n_y\f$. 
	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.

	\param vx x part of the vector field such that \f$v_x[i*n_x+j] = v_x(i,j)\f$
	\param vy y part of the vector field such that \f$v_y[i*n_x+j] = v_x(i,j)\f$ 
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetDatas(const std::vector<int>& vx, const std::vector<int>& vy, bool bMakeCopy = true);

	/*! \brief Setting data as vectors of double
	Sets the array $V_x$ must be of size \f$n_x \times n_y\f$. 
	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.

	\param vx x part of the vector field such that \f$v_x[i*n_x+j] = v_x(i,j)\f$
	\param vy y part of the vector field such that \f$v_y[i*n_x+j] = v_x(i,j)\f$ 
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetDatas(const std::vector<BYTE>& vx, const std::vector<BYTE>& vy, bool bMakeCopy = true);

	//! Sets the data for the vector field
	void SetDatas(CPGLDataPtr pVx, CPGLDataPtr  pVy);
	/// returns a pointer to the array $V_x$
	CPGLDataPtr		GetVx()			{	return m_pVx;};
	/// returns a pointer to the array $V_x$, const
	const CPGLDataPtr GetVx() const	{	return m_pVx;};	
	/// returns a pointer to the array $V_y$
	CPGLDataPtr		GetVy()			{	return m_pVy;};
	/// returns a pointer to the array $V_y$, const
	const CPGLDataPtr GetVy() const	{	return m_pVy;};
	//! Clears data
	void ClearData();
	//@}

	/// returns minimum value of Z
	double GetNormMin() const		{	return m_dNormMin;};
	/// returns maximum value of Z
	double GetNormMax() const		{	return m_dNormMax;};

	//! \name Line width
	//@{
	//! returns the line width (in pixels)
	float GetLineWidth() const		{	return m_fLineWidth;};
	/// sets the linewidth
	void SetLineWidth(float lw)		{	m_fLineWidth=__max(0.5f,lw);};
	//@}


	//! \name Virtual override
	//@{
	//! adds the line property page to the property sheet dialog.
	virtual void AddPropertyPage(CPropertySheet *pPropSheet);

    //! plotting function.
	virtual void PlotGfx(gfxinterface::CGfxInterface& gfx);
	/// Serialize functions
	void SerializeXML(CPGLArchive& ar);

	/// Debuggin functions
	#ifdef _DEBUG
	    virtual void Dump( CDumpContext& dc ) const;
	    virtual void AssertValid() const;   
	#endif
	//@}

protected:
	float m_fLineWidth;
    //! \name Attributes
    //@{
	/// v_x, array of n_x x n_y
	CPGLDataPtr m_pVx;
	/// v_y, array of n_x x n_y
	CPGLDataPtr m_pVy;
	//@}

private:
    //! \name Private Attributes
    //@{ 
	/// minimum of |(v_x,v_y)|
	double m_dNormMin;
	/// maximum of |(v_x,v_y)|
	double m_dNormMax;
	//@}
};

PGL_DECLARE_SMARTPTR( CPGLMapVector );

#endif // !defined(AFX_PGLMAPVECTOR_H__70867AFB_7D0F_4F2B_8187_6103E59B8EAA__INCLUDED_)
